﻿using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Threading;
using GalaSoft.MvvmLight.Command;
using XamlingCore.Infrastructure.Dialog;
using XamlingCore.Infrastructure.View.DialogView;
using XamlingCore.Infrastructure.View.Implementation;
using XamlingCore.Infrastructure.View.Interface;


namespace XamlingCore.Infrastructure.View
{
    [DataContract]
    public class ViewModelBase : NotifyBase
    {
        private DialogViewModelBase currentDialogViewModel;

        public ViewModelBase()
        {

        }

        public Dispatcher Dispatcher
        {
            get { return Application.Current.RootVisual.Dispatcher; }
        }

        public DialogViewModelBase CurrentDialogViewModel
        {
            get { return currentDialogViewModel; }
            set
            {
                currentDialogViewModel = value;
                OnPropertyChanged("CurrentDialogViewModel");
            }
        }

        public virtual void ShowDialog(ShowDialogViewModelBase dialogViewModel, System.TimeSpan timeOut, System.Action<Dialog.DialogResult> dialogResult)
        {
            if (CurrentDialogViewModel != null)
            {
                CurrentDialogViewModel.ShowDialog(dialogViewModel, timeOut, dialogResult);    
            }
        }

        public virtual void HideDialog()
        {
            CurrentDialogViewModel.HideDialog();
        }

        protected void SetActive(object obj, bool isActive)
        {
            var activeAware = obj as IActiveAware;
            if (activeAware != null)
            {
                activeAware.IsActive(false);
            }
        }
    }
}
